#include <iostream>
#include "eigen.h"


using namespace std;


void test_trash(){

    char learn[] = "learn";
    char test_tomove[] = "test";
    char uninitial[] = "unin";
    char test[]="gogo"; //includes only one image herei

    char person[] = "ben";
    //firstly add 

    DbOperation *db = new DbOperation();
    db->addAllDir(test_tomove,person,uninitial);

    vector<string> flist = vector <string>();
    
    if( (db->listImages(test_tomove,flist))!=0){
        cout << "Some error in listing "<<endl;
        return;
   }
        

    for(unsigned int i=0; i<flist.size();i++){
        
        ImageOpt *parsed_name = new ImageOpt();
        db->parseImageName(flist[i],parsed_name);
        //collect the garbage 
        delete parsed_name;

        char temp_f[]="1_hah_1.pgm";
        char temp_src[256];
        strcpy(temp_src,flist[i].c_str());

        db->moveFile(test_tomove,test,temp_src,temp_f,0);
        //cout << flist[i] << endl;
        //before remove it do the job
        EigenTest *e = new EigenTest();
        e->recognize(test,learn);
        delete e;
        db->removePerson("hah",test);
    }

    //now copy one by one and test


}

int main(int argc,char* argv[]){
    // burada yapılanlar sadece test edilecek

    if(argc < 2){
        cout << "There is no argument like that " << endl;
        return 1;

    }

    if (strcmp(argv[1],"tester")==0){
        test_trash();        
        return 0;
    }


    if (strcmp(argv[1],"rmperson")==0){
        DbOperation *db = new DbOperation();
        if(db ->removePerson(argv[2],argv[3])==false){
            cout << "Error in deleting person " << endl;
            delete db;
            return 1;

        }
        else{
            delete db;
            return 0;
        }
    }

    if (strcmp(argv[1],"rmimage")==0){
        DbOperation *db = new DbOperation();
        if(db ->removeImage(argv[2],argv[3])==false){
            cout << "Error in deleting image " << endl;
            delete db;
            return 1;

        }
        else{
            delete db;
            return 0;
        }
    }


    //adding a single image
    if (strcmp(argv[1],"addimage")==0){
        DbOperation *db = new DbOperation();
        if(db ->addImage(argv[2],argv[3],argv[4],argv[5])==false){
            cout << "Error in adding images " << endl;
            delete db;
            return 1;

        }
        else{
            delete db;
            return 0;
        }
    }

    //adding a whole directory

    if (strcmp(argv[1],"addall")==0){
        DbOperation *db = new DbOperation();
        if(db ->addAllDir(argv[2],argv[3],argv[4])==false){
            cout << "Error in adding directory " << endl;
            delete db;
            return 1;

        }
        else{
            delete db;
            return 0;
        }
    }



    if(strcmp(argv[1],"list")==0){
        //the list part here
        DbOperation *db = new DbOperation();
        db->printImages(argv[2]);
        delete db;
    }
    else{ 
        if(strcmp(argv[1],"learn")==0){
        EigenLearn *el = new EigenLearn();
        el->learn(argv[2]);
        delete el;
    }
        else{
             if(strcmp(argv[1],"test")==0){
                 EigenTest *et = new EigenTest();
                 et->recognize(argv[2],argv[3]);
                 delete et;
             }
             else{
            cout <<"Command not recognized"<<endl;
            return 1;
             }
    }

    }

    return 0;
}


